from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, DATE

# 创建对象的基类
Base = declarative_base()

# 生成结果历史类
class label(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_FX_TITLE'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    YEAR = Column(VARCHAR2(36))
    STARTMONTH = Column(VARCHAR2(36))
    ENDMONTH = Column(VARCHAR2(36))
    FXLX = Column(VARCHAR2(36))
    GSMC = Column(VARCHAR2(128))

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID      = int(data.get('ID')) if data.get('ID') is not None else 0,
            YEAR    = data.get('YEAR'),
            STARTMONTH    = data.get('STARTMONTH'),
            ENDMONTH      = data.get('ENDMONTH'),
            FXLX    = data.get('FXLX'),
            GSMC    = data.get('GSMC')
        )

    def to_dict(self):
        return {
            'ID':       self.ID,
            'GSMC':     self.GSMC,
            'YEAR':     self.YEAR,
            'STARTMONTH':     self.STARTMONTH,
            'ENDMONTH':       self.ENDMONTH,
            'FXLX':     self.FXLX
        }

